﻿using System;
using System.Linq;
using System.IO;
using System.IO.IsolatedStorage;
using System.Collections.Generic;
using Microsoft.LightSwitch;
using Microsoft.LightSwitch.Framework.Client;
using Microsoft.LightSwitch.Presentation;
using Microsoft.LightSwitch.Presentation.Extensions;

namespace LightSwitchApplication
{
    public partial class CreateNewContact
    {
        partial void CreateNewContact_InitializeDataWorkspace(List<IDataService> saveChangesTo)
        {
            this.ContactProperty = new Contact();
            if (this.ShopId != 0)
            {
                this.ContactProperty.ContactShop = this.DataWorkspace.ApplicationData.Shops.Where(e => e.Id == this.ShopId).FirstOrDefault();
            }
            if (this.CustomerId != 0)
            {
                this.ContactProperty.ContactCustomer = this.DataWorkspace.ApplicationData.Customers.Where(e => e.Id == this.CustomerId).FirstOrDefault();
            }
            if (this.SalesPersonId != 0)
            {
                this.ContactProperty.ContactSalesPerson = this.DataWorkspace.ApplicationData.SalesPersons.Where(e => e.Id == this.SalesPersonId).FirstOrDefault();
            }
        }

        partial void CreateNewContact_Saved()
        {
            // Write your code here.
            this.Close(false);
            Application.Current.ShowContactDetail(this.ContactProperty.Id);
        }

        partial void Cancel_Execute()
        {
            this.Close(false);
        }
    }
}